//
//  YTFTabbarViewController.m
//  weibo_yoo_OC
//
//  Created by pro on 16/2/27.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "YTFTabbarViewController.h"
#import "YTFHomeViewController.h"
#import "YTFMessageViewController.h"
#import "YTFFindViewController.h"
#import "YTFSettingViewController.h"
#import "YTFTabBar.h"
#import "YTFBasicNavController.h"

@interface YTFTabbarViewController ()

@end

@implementation YTFTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //实例化一个自定义的tabbar
    YTFTabBar *tabbar = [[YTFTabBar alloc]init];
    
    //因为tabBar是只读属性，不能直接赋值，所以使用KVC来给这个属性赋值
//    self.tabBar = tabbar;
    [self setValue:tabbar forKey:@"tabBar"];
    
    //给按钮添加响应事件
    [tabbar.composeButton addTarget:self action:@selector(composeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    //设置子控制器
    [self addChildViewController];
    
}

//设置子控制器
-(void)addChildViewController{
    
    YTFHomeViewController *homeVC = [[YTFHomeViewController alloc]init];
    [self addChildViewControllerWithChildViewController:homeVC andWithTitle:@"首页" andWithImage:@"tabbar_home"];
    
    YTFMessageViewController *messageVC = [[YTFMessageViewController alloc]init];
    [self addChildViewControllerWithChildViewController:messageVC andWithTitle:@"消息" andWithImage:@"tabbar_message_center"];
    
    YTFFindViewController *findVC = [[YTFFindViewController alloc]init];
    [self addChildViewControllerWithChildViewController:findVC andWithTitle:@"发现" andWithImage:@"tabbar_discover"];
    
    YTFSettingViewController *settingVC = [[YTFSettingViewController alloc]init];
    [self addChildViewControllerWithChildViewController:settingVC andWithTitle:@"设置" andWithImage:@"tabbar_profile"];

}


//提取添加自控制器的方法
-(void)addChildViewControllerWithChildViewController:(UIViewController*)childViewController andWithTitle:(NSString*)title andWithImage:(NSString*)image{
    
    //将该控制器设置为导航控制器的根控制器
//    UINavigationController *navVC = [[UINavigationController alloc]initWithRootViewController:childViewController];
//    navVC.navigationBar.tintColor = [UIColor orangeColor];
    
    YTFBasicNavController *navVC = [[YTFBasicNavController alloc]initWithRootViewController:childViewController];
    
    
    //设置childViewController
    childViewController.title = title;
    childViewController.tabBarItem.image = [UIImage imageNamed:image];
    childViewController.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",image]];
    
    //将该导航控制器添加到tabbarViewController上
    [self addChildViewController:navVC];
}


-(void)composeButtonClick{
    NSLog(@"composeButtonClick");
}



@end
